<?php
namespace BoxEdu\Controller\Admin;
//use Think\Controller;

class SchoolController extends CommonController {
	public function _initialize() {
		parent::_initialize();
		$school_cate_name_list = array(
			'重点本科院校', '本科院校', '独立本科院校', '专科院校', '民办院校', '学习中心',
		);
		dict("school_cate_name_list", $school_cate_name_list);
		$this->school_cate_name_list = dict("school_cate_name_list");
	}

	/******线下课程管理****/
	public function subject() {
		$where = "is_show=1";
		if ($this->subject_id = I('subject_id')) {
			$where .= " and subjectid='$this->subject_id'";
		}
		if ($this->kw = I('kw')) {
			$where .= " and name like '%$this->kw%'";
		}
		$model = BoxModel('edu_offline_subject');
		$this->subject_list = BoxModel("edu_subject")->get("S.is_show=1");
		$data = $model->get($where, 50);
		$this->data = $data['list'];
		$this->page = $data['pager']->show;
		$this->display();
	}

	public function bing_subject() {
		$id = I('id');
		$model = BoxModel('edu_offline_subject');
		$model->where("id='$id'")->save(array('bing' => I('bing')));
	}

	/******添加线下课程管理****/
	public function add_subject() {
		$id = I('id');
		$model = BoxModel('edu_offline_subject');
		$this->data = $model->load($id);
		$this->subject_list = BoxModel("edu_subject")->get("S.is_show=1");
		//dump( BoxModel("edu_subject"));
		if (IS_POST) {
			$row = $model->create();
			if ($row['id']) {
				$model->save($row);
				$this->jump("修改成功");
			} else {
				$row['add_time'] = date("Y-m-d H:i:s");
				$model->add($row);
				$this->jump("添加成功", U('School/subject'));
			}
		}
		$this->display();
	}

	/******添加线下课程管理****/
	public function del_subject() {
		$id = I('id');
		$model = BoxModel('edu_offline_subject');
		$this->data = $model->load($id);
		if ($id) {
			$row = $model->where("id='$id'")->save(array('is_show' => 2));
			BoxModel("edu_classrooms_subject")->where(array('offline_subject_id' => $id))->delete();
			$this->jump();
		}

	}

	/******学校管理****/
	public function index() {
		$where = "is_show=1";
		if ($this->province_id = I('province_id')) {
			$where .= " and province_id='$this->province_id'";
		}
		if ($this->kw = I('kw')) {
			$where .= " and name like '%$this->kw%'";
		}
		if ($this->cate_name = I('cate_name')) {
			$where .= " and cate_name like '%$this->cate_name%'";
		}
		$model = BoxModel('EduSchools');
		$this->province_list = BoxModel("SystemArea")->Childs("0");
		$data = $model->get($where, 50, "name");
		$this->data = $data['list'];
		// $this->page = $data['pager']->show;
		$this->show_page($data['pager']);
		$this->display();
	}

	/*****设置价格***/
	public function set_offline_subject_price() {
		$school_id = I('school_id');
		$model = BoxModel('EduSchools');
		$this->data = $model->load($school_id);
		$offline_subject_list = BoxModel("edu_offline_subject_price")->get(array('school_id' => $school_id));
		$offline_subject_list2 = array();
		foreach ($offline_subject_list as $one) {
			$offline_subject_list2[$one['offline_subject_id']] = $one;
		}

		$subject_list = BoxModel("edu_subject")->get(array('is_show' => 1, 'status' => 1, 'parent_id' => 0));
		foreach ($subject_list as $k => $one) {
			$subject_list[$k]['price'] = $offline_subject_list2[$one['subjectid']]['price'];
			$subject_list[$k]['apply'] = $offline_subject_list2[$one['subjectid']]['apply'];
			$subject_list[$k]['offline'] = $offline_subject_list2[$one['subjectid']]['offline'];
			$subject_list[$k]['commission'] = $offline_subject_list2[$one['subjectid']]['commission'];
			$subject_list[$k]['constant'] = $offline_subject_list2[$one['subjectid']]['constant'];

		}
		//dump($offline_subject_list);
		//dump($subject_list);exit();
		$this->offline_subject_list = $subject_list;
		if (IS_POST) {
			BoxModel('edu_offline_subject_price')->where(array('school_id' => $school_id))->delete();
			//exit();
			$data = I('data');
			foreach ($data as $k => $one) {
				$row = array(
					'offline_subject_id' => $k,
					'school_id' => I('school_id'),
					'price' => $one['price'],
					'apply' => $one['apply'],
					'offline' => $one['offline'],
					'commission' => $one['commission'],
					'constant' => $one['constant'],
				);
				BoxModel('edu_offline_subject_price')->add($row);
			}
			$this->jump("设置成功");
		}
		$this->display();
	}

	/*****设置价格***/
	public function buy_setting() {
		$this->school_id = $school_id = I('school_id');
		$model = BoxModel('EduSchools');
		$data = $model->load($school_id);
		$this->school_name = $data['name'];
		$this->data = json_decode($data['buy_setting'], true);
		//	dump($this->data);
		if (IS_POST) {
			$row['buy_setting'] = json_encode(array('apply' => I('apply'), 'offline' => I('offline')));
			$r = $model->where(array('id' => $school_id))->save($row);
			$this->jump("设置成功");
		}
		$this->display();
	}

	/******添加学校****/
	public function add_school() {
		$id = I('id');
		$this->memuNav = "index";
		$model = BoxModel('EduSchools');
		$this->data = $model->load($id);
		$this->province_list = BoxModel("SystemArea")->Childs("0");
		if (IS_POST) {
			$row = $model->create();
			if ($row['id']) {
				$model->save($row);
				$this->jump("修改成功");
			} else {
				$row['add_time'] = date("Y-m-d H:i:s");
				$model->add($row);
				$this->jump("添加成功", U('School/index'));
			}
		}
		$this->display();
	}

	public function get_ajax_school_sel() {
		$model = BoxModel('EduSchools');
		if ($this->province_id = I('get.province_id')) {
			$where = " province_id='$this->province_id'";
		}
		$this->schools_list = $model->get($where, "", "name");
		$this->display();
	}

	/******添加学校****/
	public function del_school() {
		$id = I('id');
		$this->data = BoxModel('EduSchools')->load($id);
		$is_show = $this->data['is_show'] == 1 ? 2 : 1;
		BoxModel('EduSchools')->where(array('id' => $id))->save(array('is_show' => $is_show));
		BoxModel("edu_offline_subject_price")->where("school_id='$id'")->delete();
		$this->jump("删除成功");
	}

	/******班级管理****/
	public function classroom() {
		$this->province_list = BoxModel("SystemArea")->Childs("0");
		$this->schools_list = BoxModel('EduSchools')->get("is_show=1");
		$where = "is_show=1";
		if ($this->province_id = I('province_id')) {
			$where .= " and province_id='$this->province_id'";
		}
		if ($this->school_id = I('school_id')) {
			$where .= " and school_id='$this->school_id'";
		}
		if ($this->kw = I('kw')) {
			$where .= " and name like '%$this->kw%'";
		}
		$data = BoxModel("EduClassrooms")->get($where, 8);
		$this->data = $data['list'];
		$this->page = $data['pager']->show;
		$this->display();
	}

	public function get_ajax_classrooms_sel() {
		$model = BoxModel('EduClassrooms');
		if ($this->school_id = I('get.school_id')) {
			$where = " school_id='$this->school_id' and is_show=1";
		}
		$this->class_id = I('class_id');
		$this->classrooms_list = $model->get($where);
		$this->display();
	}

	/******添加班级****/
	public function add_classroom() {
		$this->memuNav = "classroom";
		$this->province_list = BoxModel("SystemArea")->get("pid=0");
		$this->schools_list = BoxModel('EduSchools')->get();
		// $this->subject_list = BoxModel('edu_subject')->get("is_show=1 and status=1", "", "order_by");
		$this->subject_list = BoxModel("EduSubject")->tree();
		// dump($this->subject_list);
		$model = BoxModel("EduClassrooms");
		$id = I('id');
		$this->data = $model->load($id);
		$this->setting = $this->data['encode_setting'] ? $this->data['encode_setting'] : "{}";
		if (IS_POST) {
			$row = $model->create();
			$row['seat_num'] = $row['line_num'] * $row['row_num'];
			$setting = stripslashes(htmlspecialchars_decode($_POST['setting'])); //防止标签转义
			$setting = json_decode($setting, true);
			if ($class_room_id = $row['id']) {
				$model->save($row);
				$url = "";
			} else {
				$row['add_time'] = date("Y-m-d H:i:s");
				$class_room_id = $model->add($row);
				$url = U('School/classroom');
			}
			/***保存课程与级班关系**/
			BoxModel("edu_classrooms_subject")->where("class_room_id='$class_room_id'")->delete();
			foreach ($setting as $one) {
				foreach ($one['data'] as $row) {
					$arr = array(
						'class_room_id' => $class_room_id,
						'subjectid' => $row['subjectid'],
						'offline_subject_id' => $row['offline_subject_id'],
						'lable' => $row['lable'],
						'week' => $one['week'],
						'week_str' => $one['week_str'],
						'date' => $one['date'],
						'school_id' => I('school_id'),
						'province_id' => I('province_id'),
					);
					BoxModel("edu_classrooms_subject")->add($arr);
				}
			}
			$this->jump("操作成功", $url);
		}
		$this->display();
	}

	/******删除班级****/
	public function del_classroom() {
		$id = I('id');
		$this->data = BoxModel("EduClassrooms")->load($id);
		$is_show = $this->data['is_show'] == 1 ? 2 : 1;
		BoxModel('EduClassrooms')->save(array('id' => $id, 'is_show' => $is_show));
		if ($is_show == 2) {
			BoxModel("edu_classrooms_subject")->where(array('class_room_id' => $id))->delete();
		}
		$this->jump("删除成功");
	}

	/*****班级预约**/
	public function books() {
		$this->province_list = BoxModel("SystemArea")->Childs("0");
		$this->schools_list = BoxModel('EduSchools')->get("is_show=1");
		$where = "1  and S.status=1";
		if ($this->province_id = I('province_id')) {
			$where .= " and S.province_id='$this->province_id'";
		}
		if ($this->school_id = I('school_id')) {
			$where .= " and S.school_id='$this->school_id'";
		}
		if ($this->classrooms_id = I('classrooms_id')) {
			$where .= " and S.classroom_id='$this->classrooms_id'";
		}

		if ($this->kw = I('kw')) {
			$where .= " and  S.user_id = '%$this->kw%' or (qq like '%$this->kw%' or real_name like '%$this->kw%')";
		}

		$model = BoxModel('edu_classrooms_book');
		$count = $model->alias("S")->join("edu_students as M on M.user_id=S.user_id")->where($where)->count();
		$pager = $this->setPager($count, 10);
		$data = $model->alias("S")->join("edu_students as M on M.user_id=S.user_id")->where($where)->order('S.id desc')->join("edu_subject as O on O.subjectid=S.subject_id")->join("edu_schools as SC on SC.id=S.school_id")->field("M.*,S.*,O.subject as offline_subject_name,SC.name as school_name")->limit($this->limit)->select();
		// dump($model);
		/* foreach($data as $k=>$one){
	             $data[$k]=$model->load($one['id']);
*/
		//  dump($model);
		$this->data = $data;
		$this->display();
	}

	/******学生管理****/
	public function student() {
		$this->gender = dict('gender');
		// $this->province_list = BoxModel("SystemArea")->get("pid=0");
		// $this->schools_list = BoxModel("edu_schools")->get("is_show=1", "", "name");
		$where = "1 and ES.is_show=1 and ES.status=1";
		// if ($this->province_id = I('province_id')) {
		// 	$where .= " and ES.province_id='$this->province_id'";
		// 	$this->schools_list = BoxModel('EduSchools')->get("province_id='$this->province_id' and is_show=1", "", "name");
		// }
		// if ($this->school_id = I('school_id')) {
		// 	$where .= " and ES.school_id='$this->school_id'";
		// }

		$this->subject_list = BoxModel("edu_subject")->get("is_show=1", "", "order_by");
		$url_array = I();
		unset($url_array['p']);
		unset($url_array['order_by']);
		$this->sort_url = U("", $url_array);
		/*****排序**/
		$order_by_str = " ES.user_id desc";
		$this->sort_array = array(
			'1' => array(
				'class' => 'desc',
				'value' => 'S.money desc',
			),
			'2' => array(
				'class' => 'desc',
				'value' => 'S.money asc',
			),
			'3' => array(
				'class' => 'desc',
				'value' => 'S.integral desc',
			),
			'4' => array(
				'class' => 'desc',
				'value' => 'S.money asc',
			),
		);
		if ($this->order_by = I('order_by')) {
			$order_by_str = $this->sort_array[$this->order_by]['value'];
		}
		if ($this->subjectid = I('subjectid')) {
			$data = BoxModel("edu_subject_order")->field("user_id")->where(array('subjectid' => $this->subjectid, 'status' => 2))->select();

			$user_ids = array();
			if (is_array($data)) {
				foreach ($data as $key => $value) {
					$user_ids[$value['user_id']] = $value['user_id'];
				}
			}
			if (!empty($user_ids)) {
				$user_ids_str = implode(",", $user_ids);
				$where .= " and  ES.user_id in ($user_ids_str)";
			} else {
				$where .= " and 0 ";
			}

		}
		//dump($where);
		/*****条数**/
		$pagesize = I('pagesize', "10", "intval");
		/******条件***/
		if ($this->kw = I('kw')) {
			$where .= " and (ES.real_name like '%$this->kw%' or ES.qq like '%$this->kw%' or ES.mobile like '%$this->kw%'  )";
		}
		if ($this->user_id = I('user_id')) {
			$where = "ES.user_id='$this->user_id'";
		}
		$count = BoxModel("EduStudents")->alias("ES")->where($where)->count();
		$this->setPager($count, $pagesize);
		$data = BoxModel("EduStudents")->alias("ES")->limit($this->limit)->where($where)->field("ES.*")->order($order_by_str)->select();
		$edu_user = BoxModel("edu_user");
		foreach ($data as $k => $one) {
			$member = (array) BoxModel("system_member")->load($one['user_id']);
			$row = array_merge($one, $member);
			$data[$k] = array_merge($one, $member);
			Logic("BoxEdu", "User")->completion_member($one['user_id']);
			$row = $edu_user->where(array('user_id' => $one['user_id']))->find();
			$sync_login = BoxModel("system_sync_login")->where(array('uid' => $one['user_id']))->find();
			$data[$k]['subject_count'] = 0;
			$data[$k]['sync_login'] = $sync_login['type'];
			$row['subjectids'] = json_decode($row['subjectids'], true);
			if (is_array($row['subjectids'])) {
				$data[$k]['subject_count'] = count($row['subjectids']);
			}
		}
		$this->data = $data;
		$this->display();
	}
	//布置作业
	public function send_homework() {
		$this->user_ids = $user_ids = I('ids');
		$this->user_infos = BoxModel("system_member")->get("user_id in ($user_ids)");
		if (IS_POST) {
			$this->storeInfo = BoxModel("addon_wx_config")->load($this->admin_store_id);
			$param = array(
				'token' => $this->storeInfo['token'],
				'appID' => $this->storeInfo['appID'],
				'appsecret' => $this->storeInfo['appsecret'],
			);
			$this->wechatObj = new \Common\Org\weiXin($param);

		}
		$this->display();
	}

	/*****学生信息**/
	public function send_money() {
		$this->user_ids = $user_ids = I('ids');
		$this->remark = I('remark');
		$this->after_send = I('after_send');
		$this->money = I('money', "0", "intval");
		$this->user_infos = BoxModel("edu_students")->get("user_id in ($user_ids)");
		if (IS_POST) {
			$money = I('money');
			$remark = I('remark');
			if (!$user_ids) {
				exit("请选择用户");
			}
			if (!intval($money) > 0) {
				exit("请输入大于0的金额");
			}
			if (!$remark) {
				exit("请输入发放理由");
			}
			/******管理员发放***/
			//$num=$data['order_amount'];
			foreach ($this->user_infos as $one) {
				$row = array(
					'user_id' => $one['user_id'],
					'num' => $money,
					'title' => $remark,
					'event' => "00011",
				);
				//dump($row);
				$r = Logic('BoxSns', 'Log')->add($row);
				if ($r['error'] > 0) {
					$error = 1;
					$msg = "用户id：" . $one['user_id'] . "，发送失败，原因：" . $r['msg'];
				}
			}
			if ($error == 1) {
				exit($msg);
			} else {
				exit("发放成功");
			}
		}
		$this->display();
	}

	/*****学生信息**/
	public function student_info() {
		$user_id = I('user_id');
		$this->gender = dict("gender");
		$this->data = Logic("BoxEdu", "User")->info($user_id);
		$this->display();
	}

	/*****导入学生**/
	public function import() {
		$this->list = BoxModel("edu_offline_subject")->get("is_show=1");
		$this->display();
	}

	public function importdo() {
		if (IS_POST) {
			$file = $_FILES['excel']['tmp_name'];
			$model = Logic("BoxEdu", "User");
			if ($file) {
				ini_set('memory_limit', '1280M');
				set_time_limit(0);
				$obj = new \Common\Org\icPHPExcel();
				$obj->Load_Excel($file);
				$data = $obj->findAll();
				$sex = array(
					'男' => 1,
					'女' => 2,
				);
				$sucees = 0;
				$fail = 0;
				unset($data[1]);
				if ($data) {
					foreach ($data as $key => $value) {
						$school_name = $value['E'];
						$school_data = BoxModel("edu_schools")->where("name='$school_name'")->find();
						$add = array(
							'real_name' => $value['A'],
							'gender' => $sex[$value['B']] ? $sex[$value['B']] : "0",
							'id_card' => $value['C'],
							'birthday' => date("Y-m-d H:i:s", strtotime($value['D'])),
							'school_id' => intval($school_data['id']),
							'major_name' => $value['F'],
							'enrollment_dt' => date("Y-m-d H:i:s", strtotime($value['G'])),
							'mobile' => $value['H'],
							'qq' => $value['I'],
							'wechat_id' => $value['J'],
						);
						$qq_array[] = $value['I'];
						$r = $model->add_student($add);
						Logic("BoxEdu", "User")->completion_member($r['user_id']);
						$offline_subject_id = I('offline_subject_id');
						$this->open_courses($offline_subject_id, $r['user_id']); //开通课程
						if ($r['id']) {
							$sucees++;
							$r = "成功";
							$class = "suc";
						} elseif ($r['error'] == 1) {
							$fail++;
							$r = "QQ号重复导入";
							$class = "fail";
						} else {
							$fail++;
							$r = "失败";
							$class = "fail";
						}
						$msg .= "<p class='" . $class . "'>导入" . $r . " 姓名：" . $value['A'] . ",电话：" . $value['H'] . ",QQ：" . $value['I'] . "</p>";

					}

					/*$qq_array_ids=implode(",",$qq_array);
						                    BoxModel("edu_students")->where("qq in ($qq_array_ids)")->save(array('province_id'=>'110000','school_id'=>'1043'));
					*/
					$this->msg = $msg;
					$this->sucees = $sucees;
					$this->fail = $fail;
					$this->display("import_msg");
				}
			}
		}
	}

	function show_open_courses() {

		$this->user_id = I('id');
		$this->data = BoxModel("system_member")->load($this->user_id);
		$this->subject_list = BoxModel('edu_subject')->get("is_show=1 and status=1 and parent_id=0");
		$this->pay_type = BoxModel('system_payment')->get("state=1");
		$row = Logic("BoxEdu", "User")->info($this->user_id);
		$subject_data = array();
		foreach ($row['subjectids_info'] as $k => $one) {
			$subject_data[$one['subjectid']]['name'] = $one['subject'];
			$subject_data[$one['subjectid']]['end_date'] = $one['end_date'];
		}
		$this->subject_data = $subject_data;
		if (IS_POST) {
			$payment_id = I('payment_id');
			$user_id = $this->user_id;
			$subject_id = I('subject_id');
			if ($subject_data[$subject_id]) {
				// $this->jump("您已经开通过课程了");
			}
			$offline_subject_ids = I('offline_subject_ids', "0", "intval");
			$this->open_courses($subject_id, $user_id, $payment_id, $offline_subject_ids);
			$this->jump("开通成功");
		}
		$this->display();
	}
//删了一个课程
	public function del_courses() {
		$subjectid = I('subject_id');
		$user_id = I('user_id');
		$data = BoxModel("system_member")->load($user_id);
		$subjectids = json_decode($data['subjectids'], true);
		unset($subjectids[$subjectid]);
		BoxModel("edu_user")->where(array('user_id' => $user_id))->save(array('subjectids' => json_encode($subjectids)));
		//订单设置为退款
		BoxModel("edu_subject_order")->where(array('user_id' => $user_id, 'subjectid' => $subjectid, 'status' => array('in', "2,4")))->save(array('status' => 5));
		//删了选课记录
		$subject = BoxModel("edu_subject")->load($subjectid);
		$ids[] = $subject['subjectid'];
		if (is_array($subject['childs'])) {
			foreach ($subject['childs'] as $key => $value) {
				$ids[] = $value['subjectid'];
			}
		}
		$ids = implode(",", $ids);
		BoxModel("edu_classrooms_book")->where("user_id='$user_id' and subject_id in ($ids)")->delete();
		$this->jump("操作成功");
	}

	/******开通课程****/
	public function open_courses($subjectid, $user_id, $payment_id = 51, $offline_subject_ids = 1) {
		/*************开通线下课程*******/
		$data = array(
			'subjectid' => $subjectid,
			'type' => 1,
			'payment_id' => $payment_id,
			'offline_subject_ids' => $offline_subject_ids, //是否开通线下课程
		);
		$user_logic = Logic("BoxEdu", "User");
		$user_logic->user_id = $user_id;
		$return = $user_logic->buy_subject($data);
		//	dump($return);exit();
		if ($return['error'] == 0) {
			session("pay_sucess", true);
			$r = $user_logic->buy_subject_sucess($GLOBALS['pay_order_sn']);
		} else {
			$this->jump($return['msg']);
		}
	}

	/******学生管理****/
	public function add_student() {
		$this->memuNav = "student";
		$this->province_list = BoxModel("SystemArea")->Childs("0");
		$this->schools_list = $data['list'];
		$model = BoxModel("EduStudents");
		$id = I('id');
		$data = $model->load($id);
		if ($data) {
			$school_id = $this->data['school_id'];
			$r = BoxModel("EduClassrooms")->get("school_id='$school_id'");
			$this->classrooms_list = $r['list'];
			$member = (array) BoxModel("system_member")->load($data['user_id']);
			$data = array_merge($data, $member);
		}
		$this->data = $data;
		if ($this->data['province_id']) {
			$province_id = $this->data['province_id'];
			$this->schools_list = BoxModel("EduSchools")->get("province_id='$province_id'");
		}
		if (IS_POST) {
			$row = I();
			$r = Logic("BoxEdu", "User")->bing_student($row, "admin");
			if ($id = $r['id']) {
				$this->jump("保存成功", U('add_student', array('id' => $id)));
			} else {
				$this->jump("保存成功", U('student'));
			}
		}
		$this->display();
	}

	/******删除学生****/
	public function status_student() {
		$id = I('id');
		$this->data = BoxModel("EduStudents")->load($id);
		$is_show = 2;
		BoxModel('EduStudents')->save(array('id' => $id, 'status' => $is_show));
		BoxModel('system_sync_login')->where(array('uid' => $this->data['user_id']))->delete();
		Logic("BoxSns", "member")->dologout($this->data['user_id']); //当前用户退出登录
		$this->jump("操作成功");
	}

	/******时间安排管理****/
	public function time_list() {
		$this->province_list = BoxModel("SystemArea")->Childs("0");

		$this->week_list = array(
			'1' => '周一',
			'2' => '周二',
			'3' => '周三',
			'4' => '周四',
			'5' => '周五',
			'6' => '周六',
			'7' => '周日',
		);
		$this->offline_subject = BoxModel('edu_offline_subject')->get("is_show=1");
		$where = "1";
		if ($this->province_id = I('province_id')) {
			$where .= " and ES.province_id='$this->province_id'";
			$this->schools_list = BoxModel('EduSchools')->get("province_id='$this->province_id' and is_show=1", "", "name");
		}
		if ($this->week = I('week')) {
			$where .= " and ES.week='$this->week'";
		}

		if ($this->school_id = I('school_id')) {
			$where .= " and ES.school_id='$this->school_id'";
			$this->classrooms_list = BoxModel("EduClassrooms")->get("school_id='$this->school_id' and is_show=1", "", "name");
		}
		if ($this->class_id = I('class_id')) {
			$where .= " and ES.class_room_id='$this->class_id'";
		}
		if ($this->offline_subject_id = I('offline_subject_id')) {
			$where .= " and ES.offline_subject_id='$this->offline_subject_id'";
		}
		$count = BoxModel("edu_classrooms_subject")->alias("ES")->where($where)->count();
		$this->setPager($count, 10);
		$data = BoxModel("edu_classrooms_subject")->alias("ES")->join("left join edu_classrooms as C on C.id=ES.class_room_id")->join("left join edu_offline_subject as O on O.id=ES.offline_subject_id")->join("left join edu_schools as S on S.id=ES.school_id")->where($where)->field("ES.*,C.name as class_name,O.name as offline_subject,S.name as school_name")->select();
		// dump($data);
		$this->data = $data;

		$this->display();
	}

	//选座指南
	function offline_topic() {
		$this->subject_list = BoxModel("edu_subject")->get("is_show=1 and parent_id=0", "", "order_by");
		$data = '{"status":"1","type":"topic","title":"线下选课指南","tpl_type":"ad_topic","tpl":"","enable":"1","info":"","store_id":"1","name":"offline_guide_86","cache":"2","order_by":"999"}';
		$data = json_decode($data, true);
		$model = BoxModel("addon_blocks");
		foreach ($this->subject_list as $one) {
			$data['name'] = 'offline_guide_' . $one['subjectid'];
			$r = $model->where(array('name' => $data['name']))->find();
			if (!$r) {
				$model->add($data);
			}
		}
		//	dump(json_decode($data,true));
		$this->display();
	}

}